
cd "/Users/sergi/Library/CloudStorage/Dropbox/Work/Coconut paper/Ethnic Minority British Electoral Survey/"


global pathfig "/Users/sergi/Library/CloudStorage/Dropbox/Aplicaciones/Overleaf/Migrant political integration"

global results "/Users/sergi/Library/CloudStorage/Dropbox/Work/Coconut paper/Ethnic Minority British Electoral Survey/"



use 2010BESprepost.dta, clear

drop if  bq101 !=1 /*we select white british only in post-electoral wave*/

recode bq61 1=4 2=3 3=2 4=1 else=., gen(satdem_bes)

gen trustparl_bes=bq16_2
gen trust_politicians_bes=bq16_3
gen poltrust_bes=trustparl_bes+trust_politicians_bes

gen inter_trust_bes=bq68 /*interpersonal trust from 0 to 10*/

recode bq95_3 1/3=1 4/18=0 else=., gen(univdegree_bes)

xtile income_bes=bq96, nq(5) /*household income in 5 quintiles*/

*sum bq96, d
*gen income_bes=(bq96-r(min))/(r(max)-r(min))

gen male_bes=bq88==1

gen age_bes=bq89
drop if age_bes<18

gen vote_bes=bq12_1==1

gen volunteer_politics_bes=bq54_2==1 /*dummy yes-no*/

recode bq54_3 1=4 2=3 3=2 4=1 else=., gen(volunteer_social_bes) /*1-4 scale from less to more active*/

recode bq1 1=5 2=4 3=3 4=2 5=1 else=., gen(polinterest_bes) /*1-5 from less to more political interest*/

recode bq18_6 1=5 2=4 3=3 4=2 5=1 else=., gen(dutyvote_bes) /*1-5 agreement scale voting is a duty*/

gen influence_bes=bq59 /*0-10 scale from less to more perceived influence in politics*/

recode bq9_2 1=1 2=0 else=., gen(partyclose_bes)

recode bq98_1 1/6=0 7/8=1 9/10=0 else=., gen(workclass_bes)

keep satdem_bes trustparl_bes trust_politicians_bes poltrust_bes inter_trust_bes univdegree_bes income_bes male_bes age_bes vote_bes ///
volunteer_politics_bes volunteer_social_bes polinterest_bes dutyvote_bes influence_bes partyclose_bes workclass_bes

gen bes=1


save BES_post_short.dta, replace
use embesapr11.dta, clear

append using BES_post_short.dta




gen commonwealth=0
replace commonwealth=. if  bq102_1 < 1
replace commonwealth=1 if  bq102_1 == 5
replace commonwealth=1 if  bq102_1 == 6
replace commonwealth=1 if  bq102_1 == 7
replace commonwealth=1 if  bq102_1 == 8
replace commonwealth=1 if  bq102_1 == 13
replace commonwealth=1 if  bq102_1 == 14
replace commonwealth=1 if  bq102_1 == 15
replace commonwealth=1 if  bq102_1 == 16
replace commonwealth=1 if  bq102_1 == 17
replace commonwealth=1 if  bq102_1 == 18
replace commonwealth=1 if  bq102_1 == 19
replace commonwealth=1 if  bq102_1 == 21
replace commonwealth=1 if  bq102_1 == 23
replace commonwealth=1 if  bq102_1 == 24
replace commonwealth=1 if  bq102_1 == 25
replace commonwealth=1 if  bq102_1 == 30
replace commonwealth=1 if  bq102_1 == 40
replace commonwealth=1 if  bq102_1 == 46
replace commonwealth=1 if  bq102_1 == 47
replace commonwealth=1 if  bq102_1 == 57
replace commonwealth=1 if  bq102_1 == 61
replace commonwealth=1 if  bq102_1 == 78
replace commonwealth=1 if  bq102_1 == 79
replace commonwealth=1 if  bq102_1 == 83
replace commonwealth=1 if  bq102_1 == 92
replace commonwealth=1 if  bq102_1 == 95
replace commonwealth=1 if  bq102_1 == 96
replace commonwealth=1 if  bq102_1 == 97
replace commonwealth=1 if  bq102_1 == 99
replace commonwealth=1 if  bq102_1 == 100
replace commonwealth=1 if  bq102_1 == 101
replace commonwealth=1 if  bq102_1 == 102
replace commonwealth=1 if  bq102_1 == 108
replace commonwealth=1 if  bq102_1 == 109
replace commonwealth=1 if  bq102_1 == 113
replace commonwealth=1 if  bq102_1 == 124
replace commonwealth=1 if  bq102_1 == 125


recode bq61 1=4 2=3 3=2 4=1 else=., gen(satdem_embes)


recode bq16_2 -2/-1=., gen(trustparl_embes)

recode bq16_3 -2/-1=., gen(trust_politicians_embes)

gen poltrust_embes=trustparl_embes+trust_politicians_embes
 
gen univdegree_embes=0 if bes==.
replace univdegree_embes=1 if  bq95_3==1 & bes==.
replace univdegree_embes=1 if  bq95_3==2 & bes==.
replace univdegree_embes=1 if  eq64_2==2 & bes==.
replace univdegree_embes=1 if  eq64_2==3 & bes==.

replace bq96=. if bq96<1
xtile income_embes=bq96, nq(5)

*sum bq96, d
*gen income_embes=(bq96-r(min))/(r(max)-r(min))



recode bq88 1=1 2=0, gen(male_embes)
gen age_embes=bq89

recode bq12_1 1=1 2=0 else=., gen(vote_embes)

gen volunteer_politics_embes=.
replace  volunteer_politics_embes=1 if bq54_2==1
replace  volunteer_politics_embes=0 if bq54_2==2

recode bq54_3 1=4 2=3 3=2 4=1 else=., gen(volunteer_social_embes) /*1-4 scale from less to more active*/

recode bq1 1=5 2=4 3=3 4=2 5=1 else=., gen(polinterest_embes) /*1-5 from less to more political interest*/

recode bq18_6 1=5 2=4 3=3 4=2 5=1 else=., gen(dutyvote_embes) /*1-5 agreement scale voting is a duty*/

gen influence_embes=bq59 /*0-10 scale from less to more perceived influence in politics*/
replace influence_embes=. if bq59<0

recode bq9_2 1=1 2=0 else=., gen(partyclose_embes)

recode bq98_1 1/6=0 7/8=1 9/10=0 else=., gen(workclass_embes)

gen satdem=.
replace satdem=satdem_bes if bes==1
replace satdem=satdem_embes if bes==.

gen trustparl=.
replace trustparl=trustparl_bes if bes==1
replace trustparl=trustparl_embes if bes==.

gen trust_politicians=.
replace trust_politicians=trust_politicians_bes if bes==1
replace trust_politicians=trust_politicians_embes if bes==.

gen poltrust=.
replace poltrust=poltrust_bes if bes==1
replace poltrust=poltrust_embes if bes==.

gen univdegree=.
replace univdegree=univdegree_bes if bes==1
replace univdegree=univdegree_embes if bes==.

gen income=.
replace income=income_bes if bes==1
replace income=income_embes if bes==.

gen male=.
replace male=male_bes if bes==1
replace male=male_embes if bes==.

gen age=.
replace age=age_bes if bes==1
replace age=age_embes if bes==.

gen age2=age^2
gen age3=age^3
gen age4=age^4


gen particip=.
replace particip=vote_bes if bes==1
replace particip=vote_embes if bes==.

gen volunteer_politics=.
replace volunteer_politics=volunteer_politics_bes if bes==1
replace volunteer_politics=volunteer_politics_embes if bes==.

gen volunteer_social=.
replace volunteer_social=volunteer_social_bes if bes==1
replace volunteer_social=volunteer_social_embes if bes==.

gen polinterest=.
replace polinterest=polinterest_bes if bes==1
replace polinterest=polinterest_embes if bes==.

gen dutyvote=.
replace dutyvote=dutyvote_bes if bes==1
replace dutyvote=dutyvote_embes if bes==.

gen influence=.
replace influence=influence_bes if bes==1
replace influence=influence_embes if bes==.

gen partyclose=.
replace partyclose=partyclose_bes if bes==1
replace partyclose=partyclose_embes if bes==.

gen workclass=.
replace workclass=workclass_bes if bes==1
replace workclass=workclass_embes if bes==.


capture drop year_temp
capture drop year_arrived
gen year_temp = 2010 - bq102_2r if bq102_2r < 1947
gen year_arrived = .
replace year_arrived = bq102_2r if bq102_2r > 1946
replace year_arrived = year_temp if year_temp !=.


gen birth=2010-age
gen birth17=birth+17
sum birth17

replace year_arrived=birth17 if bes==1
drop if year_arrived<1950
drop if year_arrived>2010

set scheme gg_tableau

sort year_arrived

capture drop treated
gen treated=.
replace treated=1 if commonwealth==1
replace treated=0 if bes==1


foreach i of num  1962 1973 1983 2002 2008{
capture drop  intervention_`i' time_interv_`i' treated_time_`i' treated_interv_`i' treated_interv_time_`i'
gen time_elapsed_`i'=year_arrived-`i'
gen intervention_`i'=.
replace intervention_`i'=0 if year_arrived<`i'
replace intervention_`i'=1 if year_arrived>=`i'
gen time_interv_`i'=time_elapsed_`i'*intervention_`i'
gen treated_time_`i'=treated*time_elapsed_`i'
gen treated_interv_`i'=treated*intervention_`i'
gen treated_interv_time_`i'=treated*intervention_`i'*time_elapsed_`i'
}

gen income_log=log(income)


*DIFF-IN-DIFF models Table 1 (natives as control group)

xtset year_arrived

xtreg satdem treated intervention_1962  treated_interv_1962 male age univdegree if year_arrived<1973, fe vce(cluster year_arrived) 
est store diff1_natives
outreg2  using "${results}diff_1962_models.xls",  bdec(3) sdec(3) append

xtreg poltrust treated intervention_1962  treated_interv_1962 male age univdegree if year_arrived<1973, fe vce(cluster year_arrived) 
est store diff2_natives
outreg2  using "${results}diff_1962_models.xls",  bdec(3) sdec(3) append





*APPENDIX RESULTS RELEVANT TO DIF-IN-DIFF MODELS WITH NATIVES

*Appendix A - Table A.1: Descriptive stats

sum satdem poltrust treated intervention_1962  male age univdegree


*Appendix B: Parallel trends, models with natives as control group

 
foreach i of num  1950(1)1965 {
capture drop time_elapsed_`i' intervention_`i' time_interv_`i' treated_time_`i' treated_interv_`i' treated_interv_time_`i'
gen time_elapsed_`i'=year_arrived-`i'
gen intervention_`i'=.
replace intervention_`i'=0 if year_arrived<`i'
replace intervention_`i'=1 if year_arrived>=`i'
gen time_interv_`i'=time_elapsed_`i'*intervention_`i'
gen treated_time_`i'=treated*time_elapsed_`i'
gen treated_interv_`i'=treated*intervention_`i'
gen treated_interv_time_`i'=treated*intervention_`i'*time_elapsed_`i'
}

capture drop inter_binned
gen inter_binned =.
replace inter_binned=1 if intervention_1950==1 & intervention_1951==1
replace inter_binned=2 if intervention_1952==1 & intervention_1953==1
replace inter_binned=3 if intervention_1954==1 & intervention_1955==1
replace inter_binned=4 if intervention_1956==1 & intervention_1957==1
replace inter_binned=5 if intervention_1958==1 & intervention_1959==1
replace inter_binned=6 if intervention_1960==1 & intervention_1961==1
replace inter_binned=7 if intervention_1962==1 & intervention_1963==1
replace inter_binned=8 if intervention_1964==1 & intervention_1965==1


xtreg satdem treated##ib6.inter_binned male age univdegree if year_arrived<1973, fe vce(cluster year_arrived)



capture matrix drop coef
matrix coef = J(8, 3, .)

foreach i of num  1(1)8 {
matrix coef[`i',1]=_b[1.treated#`i'.inter_binned]
matrix coef[`i',2]=_b[1.treated#`i'.inter_binned] - _se[1.treated#`i'.inter_binned]*1.96
matrix coef[`i',3]=_b[1.treated#`i'.inter_binned] + _se[1.treated#`i'.inter_binned]*1.96
}

capture  drop coef1 coef2 coef3
capture drop beta low_ci high_ci
svmat coef
rename coef1 beta
rename coef2 low_ci
rename coef3 high_ci

capture drop axis_gr
capture label drop axis_gr
gen axis_gr=_n
replace axis_gr=. if axis_gr>8
label def axis_gr 1"1950-1951" 2"1952-1953" 3"1954-1955" 4"1956-1957" 5"1958-1959" 6"1960-1961" 7"1962-1963" 8"1964-1965"
label val axis_gr axis_gr


graph twoway (scatter  beta axis_gr if axis_gr<8, msymbol(circle) msize(small) mcolor(black) xline(6.5, lcolor(red) lp(solid)) yline(0, lcolor(black))  ///
 graphregion(color(white)) title("", size(small)) ///
 xtitle("Year of arrival", size(6)) xlabel(#7, valuelabel labsize(small)) ///
 ylabel(-1 0 1, labsize(small)) ytitle("", size(small)) legend(off)) ///
 (rspike low_ci high_ci axis_gr if axis_gr<8, lcolor(black) vertical)
 
 
 graph export "$pathfig/parallel_satdem62_natives.pdf", as(pdf) replace



xtreg poltrust treated##ib6.inter_binned male age univdegree if year_arrived<1973, fe vce(cluster year_arrived)



capture matrix drop coef
matrix coef = J(8, 3, .)

foreach i of num  1(1)8 {
matrix coef[`i',1]=_b[1.treated#`i'.inter_binned]
matrix coef[`i',2]=_b[1.treated#`i'.inter_binned] - _se[1.treated#`i'.inter_binned]*1.96
matrix coef[`i',3]=_b[1.treated#`i'.inter_binned] + _se[1.treated#`i'.inter_binned]*1.96
}

capture  drop coef1 coef2 coef3
capture drop beta low_ci high_ci
svmat coef
rename coef1 beta
rename coef2 low_ci
rename coef3 high_ci

capture drop axis_gr
capture label drop axis_gr
gen axis_gr=_n
replace axis_gr=. if axis_gr>8
label def axis_gr 1"1950-1951" 2"1952-1953" 3"1954-1955" 4"1956-1957" 5"1958-1959" 6"1960-1961" 7"1962-1963" 8"1964-1965"
label val axis_gr axis_gr


graph twoway (scatter  beta axis_gr if axis_gr<8, msymbol(circle) msize(small) mcolor(black) xline(6.5, lcolor(red) lp(solid)) yline(0, lcolor(black))  ///
 graphregion(color(white)) title("", size(small)) ///
 xtitle("Year of arrival", size(6)) xlabel(#7, valuelabel labsize(small)) ///
 ylabel(-5 0 5, labsize(small)) ytitle("", size(small)) legend(off)) ///
 (rspike low_ci high_ci axis_gr if axis_gr<8, lcolor(black) vertical)

 graph export "$pathfig/parallel_poltrust62_natives.pdf", as(pdf) replace
 
 
 
*Appendix C - Table A.5 (models with natives as control group): Unit-specific trends

gen trend=year_arrived-1950

xtreg satdem treated intervention_1962  treated_interv_1962 treated##c.trend male age univdegree if year_arrived<1973, fe vce(cluster year_arrived) 
est store diff5_natives

xtreg poltrust treated intervention_1962  treated_interv_1962 treated##c.trend male age univdegree if year_arrived<1973, fe vce(cluster year_arrived) 
est store diff6_natives



*Appendix D - Table A.6: With year dummies

reg satdem treated intervention_1962  treated_interv_1962 male age univdegree i.year_arrived if year_arrived<1973, vce(cluster year_arrived) 


reg poltrust treated intervention_1962  treated_interv_1962 male age univdegree i.year_arrived if year_arrived<1973, vce(cluster year_arrived) 




*Appendix E - Table A.7: Without fixed effects


xtreg satdem treated intervention_1962  treated_interv_1962 male age univdegree if year_arrived<1973, re vce(cluster year_arrived) 

xtreg poltrust treated intervention_1962  treated_interv_1962 male age univdegree if year_arrived<1973, re vce(cluster year_arrived) 



*Appendix F - Table A.8: Weighting by propensity to get treated

capture drop propensity 
logit treated male age univdegree year_arrived
predict propensity, pr


reg satdem treated intervention_1962  treated_interv_1962 male age univdegree if year_arrived<1973 [aweight=propensity], vce(cluster year_arrived) 
est store weighted1_natives

reg poltrust treated intervention_1962  treated_interv_1962 male age univdegree if year_arrived<1973 [aweight=propensity], vce(cluster year_arrived) 
est store weighted2_natives

*APPENDDIX I - Table A.10: Political interest

*Interest in origin country

recode eq56 1=5 2=4 3=3 4=2 5=1 else=., gen(interest_origin)


xtreg interest_origin  intervention_1962   male age univdegree if year_arrived<1973 & treated==1, re vce(cluster year_arrived) 
est store interest_origin_62


xtreg polinterest  intervention_1962   male age univdegree if year_arrived<1973 & treated==1, re vce(cluster year_arrived) 


*Appendix J - Table A.12: comparing natives identical age range

sum age if year_arrived>=1948 & year_arrived<=1961 & treated==1 
sum age if year_arrived>=1962 & year_arrived<=1972 & treated==1 
sum age if year_arrived>=1973 & year_arrived<=1982 & treated==1 

xtreg satdem treated intervention_1962  treated_interv_1962 male age univdegree if year_arrived<1973 & age>=49 & age<=89, fe vce(cluster year_arrived) 
est store diff1_age

xtreg poltrust treated intervention_1962  treated_interv_1962 male age univdegree if year_arrived<1973 & age>=49 & age<=89, fe vce(cluster year_arrived) 
est store diff2_age


*Appendix K - Table A.13: without Uganda and Kenya


numlabel bq102_1, add
tab bq102_1

gen east_africa=0
replace east_africa=1 if bq102_1==25
replace east_africa=1 if bq102_1==16



xtreg satdem treated intervention_1962  treated_interv_1962 male age univdegree if year_arrived<1973 & east_africa==0, fe vce(cluster year_arrived) 
est store diff1_eastafrica

xtreg poltrust treated intervention_1962  treated_interv_1962 male age univdegree if year_arrived<1973 & east_africa==0, fe vce(cluster year_arrived) 
est store diff2_eastafrica



*Appendix N - Table A.18: Natives Only

reg satdem  intervention_1962  male age univdegree if year_arrived<1973 & treated==0, vce(cluster year_arrived) 
reg poltrust  intervention_1962  male age univdegree if year_arrived<1973 & treated==0, vce(cluster year_arrived) 



*Appendix O - Table A.19: factor variable as dependent variable

factor satdem poltrust
rotate, varimax
predict overall_factor

xtreg overall_factor treated intervention_1962  treated_interv_1962 male age univdegree if year_arrived<1973, fe vce(cluster year_arrived) 





*TABLE 2- ITS models with natives as control group and figures Appendix G



reg satdem time_elapsed_1962 intervention_1962 time_interv_1962 treated treated_time_1962 treated_interv_1962 treated_interv_time_1962 male age univdegree, vce(cluster year_arrived) /*promising*/

est store its_inc1


est restore its_inc1

capture drop mv
gen mv=_n-1 if _n<11

matrix define its2_beta=e(b)
scalar define int_1962=its2_beta[1,6]
scalar define slope_1962=its2_beta[1,7]
matrix define its2_v=e(V)
scalar define var_int=its2_v[6,6]
scalar define var_slope=its2_v[7,7]
scalar define covar_inter_slope=its2_v[6,7]

capture drop marginal_unemp_1962 error_unemp_1962 upper_unemp_1962 lower_unemp_1962

gen marginal_unemp_1962=int_1962+(slope_1962*mv)
gen error_unemp_1962=sqrt(var_int+var_slope*(mv^2)+2*covar_inter_slope*mv)
gen upper_unemp_1962=marginal_unemp_1962+(1.96*error_unemp_1962)
gen lower_unemp_1962=marginal_unemp_1962-(1.96*error_unemp_1962)


graph twoway scatter marginal_unemp_1962 mv || rspike upper_unemp_1962 lower_unemp_1962 mv, lc(black) xlabel(0(1)9) ///  
 yline(0, lcolor(black) lpattern(solid)) ylabel(-1 0 1) yline(0) xtitle(Years after policy change, size(6)) ytitle(1962 policy effect, size(6)) legend(off)
 
 
 graph export "$pathfig/its_satdem62_natives.pdf", as(pdf) replace


reg poltrust time_elapsed_1962 intervention_1962 time_interv_1962 treated treated_time_1962 treated_interv_1962 treated_interv_time_1962 male age univdegree, vce(cluster year_arrived) 

est store its_unemp1




est restore its_unemp1

capture drop mv
gen mv=_n-1 if _n<11

matrix define its2_beta=e(b)
scalar define int_1962=its2_beta[1,6]
scalar define slope_1962=its2_beta[1,7]
matrix define its2_v=e(V)
scalar define var_int=its2_v[6,6]
scalar define var_slope=its2_v[7,7]
scalar define covar_inter_slope=its2_v[6,7]

capture drop marginal_unemp_1962 error_unemp_1962 upper_unemp_1962 lower_unemp_1962

gen marginal_unemp_1962=int_1962+(slope_1962*mv)
gen error_unemp_1962=sqrt(var_int+var_slope*(mv^2)+2*covar_inter_slope*mv)
gen upper_unemp_1962=marginal_unemp_1962+(1.96*error_unemp_1962)
gen lower_unemp_1962=marginal_unemp_1962-(1.96*error_unemp_1962)


graph twoway scatter marginal_unemp_1962 mv || rspike upper_unemp_1962 lower_unemp_1962 mv, lc(black) xlabel(0(1)9) ///  
 yline(0, lcolor(black) lp(solid)) ylabel(-3 0 3) yline(0) xtitle(Years after policy change, size(6)) ytitle(1962 policy effect, size(6)) legend(off)
 
 graph export "$pathfig/its_poltrust62_natives.pdf", as(pdf) replace



*Appendix H - Prais-Winsten regression


sort year_arrived

preserve /*run this in one go until last PRAIS model*/
collapse (mean) satdem poltrust time_elapsed_1962 intervention_1962 time_interv_1962  treated_time_1962 treated_interv_1962 treated_interv_time_1962 time_elapsed_1973 intervention_1973 time_interv_1973  treated_time_1973 treated_interv_1973 treated_interv_time_1973 male age univdegree, by(year_arrived treated)

tsset treated year_arrived 


prais satdem time_elapsed_1962 intervention_1962 time_interv_1962 treated treated_time_1962 treated_interv_1962 treated_interv_time_1962 male age univdegree, vce(robust)
est store prais_satdem_62

prais poltrust time_elapsed_1962 intervention_1962 time_interv_1962 treated treated_time_1962 treated_interv_1962 treated_interv_time_1962 male age univdegree, vce(robust)
est store prais_poltrust_62


